home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / threads / unixtime.c < prev    next >
C/C++ Source or Header  |  1996-02-04  |  1KB  |  83 lines

  1.  
  2.  
  3. /*
  4.  *
  5.  *    Copyright (c) 1993-1996 Algorithms Corporation
  6.  *    3020 Liberty Hills Drive
  7.  *    Franklin, TN  37067
  8.  *
  9.  *    ALL RIGHTS RESERVED.
  10.  *
  11.  *
  12.  *
  13.  */
  14.  
  15.  
  16.  
  17.  
  18. #include <stdio.h>
  19. #include <sys/time.h>
  20. #include <signal.h>
  21.  
  22.  
  23. #ifdef TEST
  24. int   _tick_count = 10000;
  25. #else
  26. extern int   _tick_count;
  27. #endif
  28.  
  29. static  void  catch_timer(int sig)
  30. {
  31.     (void) sig;  /*  avoid compiler warning  */
  32.     if (_tick_count)
  33.         _tick_count--;
  34.     signal(SIGVTALRM, catch_timer);
  35. }
  36.  
  37.  
  38. void _start_timer(void)
  39. {
  40.     struct itimerval tval;
  41.  
  42.     signal(SIGVTALRM, catch_timer);
  43.     tval.it_interval.tv_sec = 0L;
  44.     tval.it_interval.tv_usec = 54645L; /*  ~ 18/sec (single clock tick  */
  45.     tval.it_value = tval.it_interval;
  46.     setitimer(ITIMER_VIRTUAL, &tval, NULL);
  47. }
  48.  
  49.  
  50. #ifdef TEST
  51.  
  52. main()
  53. {
  54.     int n;
  55.     long i;
  56.  
  57.     _start_timer();
  58.     for (n=0 ; n++ != 10 ; )  {
  59.         fprintf(stderr, "Timer = %d\n", _tick_count);
  60.         for (i=0L ; i++ != 1000000 ; );
  61.     }
  62.     return(0);
  63. }
  64.  
  65. #endif
  66.  
  67.  
  68.  
  69. /*
  70.  *
  71.  *    Copyright (c) 1993-1996 Algorithms Corporation
  72.  *    3020 Liberty Hills Drive
  73.  *    Franklin, TN  37067
  74.  *
  75.  *    ALL RIGHTS RESERVED.
  76.  *
  77.  *
  78.  *
  79.  */
  80.  
  81.  
  82.  
  83.